package com.lanchetech.merchant.controller;

import com.lanchetech.bean.request.*;
import com.lanchetech.bean.vo.*;
import com.lanchetech.entity.*;
import com.lanchetech.merchant.aop.OperatorLog;
import com.lanchetech.merchant.service.ProductService;
import com.lanchetech.bean.response.BasePageResp;
import com.lanchetech.bean.response.BaseResp;
import com.lanchetech.bean.response.ResultData;
import com.lanchetech.bean.response.SpuResp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "商品接口", tags = "商品接口")
@RequestMapping("/api/product")
@RestController
public class ProductController {

    @Autowired
    ProductService productService;

    @ApiOperation("获取商品SPU分页")
    @PreAuthorize("hasAuthority('product.spu')")
    @PostMapping("/getSpuPage")
    public ResultData<BasePageResp<SpuResp>> getSpuPage(@RequestBody SpuReq req) {
        return productService.getSpuPage(req);
    }

    @ApiOperation("获取商品SKU列表")
    @PostMapping("/getSkuList")
    public ResultData<BasePageResp<Sku>> getSkuList(@RequestBody PageReq req) {
        return productService.getSkuList(req);
    }

    @ApiOperation("获取商品SPU和SKU列表分页")
    @PostMapping("/getProductPage")
    public ResultData<BasePageResp<SpuResp>> getProductPage(@RequestBody SpuReq req) {
        return productService.getProductPage(req);
    }

    @OperatorLog("添加或编辑商品")
    @ApiOperation("添加或编辑商品")
    @PreAuthorize("hasAuthority('product.spu.edit.auth')")
    @PostMapping("/editSpuAndSku")
    public BaseResp editSpuAndSku(@RequestBody SpuEditVO spuEditVO) {
        return productService.editSpuAndSku(spuEditVO);
    }

    @ApiOperation("获取商品")
    @PreAuthorize("hasAuthority('product.spu-edit')")
    @GetMapping("/getSpuEditDetail")
    public ResultData<SpuEditVO> getSpuEditDetail(@RequestParam("id") Long id) {
        return productService.getSpuEditDetail(id);
    }

    @ApiOperation("获取销售属性分页")
    @PreAuthorize("hasAuthority('product.spec')")
    @PostMapping("/getSpecPage")
    public ResultData<BasePageResp<Spec>> getSpecPage(@RequestBody PageReq req) {
        return productService.getSpecPage(req);
    }

    @ApiOperation("获取销售属性列表")
    @GetMapping("/getSpecList")
    public ResultData<List<Spec>> getSpecList() {
        return productService.getSpecList();
    }


    @ApiOperation("获取单位分页")
    @PreAuthorize("hasAuthority('product.unit')")
    @PostMapping("/getUnitPage")
    public ResultData<BasePageResp<Unit>> getUnitPage(@RequestBody PageReq req) {
        return productService.getUnitPage(req);
    }

    @ApiOperation("获取单位列表")
    @GetMapping("/getUnitList")
    public ResultData<List<Unit>> getUnitList() {
        return productService.getUnitList();
    }

    @ApiOperation("获取运费模板分页")
    @PreAuthorize("hasAuthority('product.freight')")
    @PostMapping("/getFreightPage")
    public ResultData<BasePageResp<Freight>> getFreightPage(@RequestBody PageReq req) {
        return productService.getFreightPage(req);
    }

    @OperatorLog("添加或编辑运费模板")
    @ApiOperation("添加或编辑运费模板")
    @PreAuthorize("hasAuthority('product.freight.edit.auth')")
    @PostMapping("/editFreight")
    public BaseResp editFreight(@RequestBody FreightVO freightVO) {
        return productService.editFreight(freightVO);
    }

    @ApiOperation("获取运费模板详情")
    @PreAuthorize("hasAuthority('product.freight-edit')")
    @GetMapping("/getFreightDetail")
    public ResultData<FreightVO> getFreightDetail(@RequestParam("id") Long id) {
        return productService.getFreightDetail(id);
    }

    @OperatorLog("删除运费模板")
    @ApiOperation("删除运费模板")
    @PreAuthorize("hasAuthority('product.freight.delete.auth')")
    @GetMapping("/deleteFreight")
    public BaseResp deleteFreight(@RequestParam("id") Long id) {
        return productService.deleteFreight(id);
    }

    @ApiOperation("获取运费模板列表")
    @GetMapping("/getFreightList")
    public ResultData<List<Freight>> getFreightList() {
        return productService.getFreightList();
    }

    @OperatorLog("编辑商品的佣金")
    @ApiOperation("编辑商品的佣金")
    @PreAuthorize("hasAuthority('product.spu.commission.auth')")
    @PostMapping("/editSpuCommission")
    public BaseResp editSpuCommission(@RequestBody SpuCommission spuCommission) {
        return productService.editSpuCommission(spuCommission);
    }

    @ApiOperation("删除商品")
    @PreAuthorize("hasAuthority('product.spu.delete.auth')")
    @GetMapping("/deleteProduct")
    public BaseResp deleteProduct(@RequestParam("id") Long id) {
        return productService.deleteProduct(id);
    }

    @ApiOperation("商户上下架商品")
    @GetMapping("/editProductHidden")
    public BaseResp editProductHidden(@RequestParam("id") Long id) {
        return productService.editProductHidden(id);
    }

    @ApiOperation("批量上下架商品")
    @PostMapping("/batchOfflineProduct")
    public BaseResp batchOfflineProduct(@RequestBody BatchOfflineReq req) {
        return productService.batchOfflineProduct(req);
    }

    @ApiOperation("排序重置")
    @GetMapping("/resetSorts")
    public BaseResp resetSorts(@RequestParam("startNum") Long startNum ,@RequestParam("endNum") Long endNum) {
        return productService.resetSorts(startNum,endNum);
    }

    @ApiOperation("修改供货价")
    @PostMapping("/editChangePrice")
    public BaseResp editChangePrice(@RequestBody EditChangePriceReq req) {
        return productService.editChangePrice(req);
    }

    @ApiOperation("获取商家后台统计数据")
    @PostMapping("/getShopStatisticsData")
    public ResultData<ShopStatisticsDataVO> getShopStatisticsData(@RequestBody TimeRangeReq req) {
        return productService.getShopStatisticsData(req);
    }

    @ApiOperation("获取商品点击人数趋势")
    @PostMapping("/getSpuClickTrend")
    public ResultData<SpuTrendVO> getSpuClickTrend(@RequestBody TimeRangeReq req) {
        return productService.getSpuClickTrend(req);
    }

    @ApiOperation("获取商品访客趋势")
    @PostMapping("/getSpuVisitorTrend")
    public ResultData<SpuTrendVO> getSpuVisitorTrend(@RequestBody TimeRangeReq req) {
        return productService.getSpuVisitorTrend(req);
    }

    @ApiOperation("获取商品退款订单量趋势")
    @PostMapping("/getSpuRefundCountTrend")
    public ResultData<SpuTrendVO> getSpuRefundCountTrend(@RequestBody TimeRangeReq req) {
        return productService.getSpuRefundCountTrend(req);
    }

    @ApiOperation("获取成交订单趋势")
    @PostMapping("/getSpuCompleteTrend")
    public ResultData<SpuTrendVO> getSpuCompleteTrend(@RequestBody TimeRangeReq req) {
        return productService.getSpuCompleteTrend(req);
    }

    @ApiOperation("获取成交人数趋势")
    @PostMapping("/getSpuCustomerTrend")
    public ResultData<SpuTrendVO> getSpuCustomerTrend(@RequestBody TimeRangeReq req) {
        return productService.getSpuCustomerTrend(req);
    }

    @ApiOperation("编辑专区")
    @PostMapping("/editZone")
    public BaseResp editZone(@RequestBody ZoneReq req) {
        return productService.editZone(req);
    }

    @ApiOperation("获取专区分页")
    @PostMapping("/getZonePage")
    public ResultData<BasePageResp<Zone>> getZonePage(@RequestBody ZonePageReq req) {
        return productService.getZonePage(req);
    }

    @ApiOperation("获取专区商品详情")
    @GetMapping("/getZoneSpuDetail")
    public ResultData<ZoneVO> getZoneSpuDetail(@RequestParam("zoneId") Long zoneId) {
        return productService.getZoneSpuDetail(zoneId);
    }

    @ApiOperation("删除专区")
    @GetMapping("/deleteZone")
    public BaseResp deleteZone(@RequestParam("zoneId") Long zoneId) {
        return productService.deleteZone(zoneId);
    }

    @ApiOperation("设置商品商家类目")
    @GetMapping("/editSpuShopCategory")
    public BaseResp editSpuShopCategory(@RequestParam("spuId") Long spuId,@RequestParam("scThirdId") Long scThirdId) {
        return productService.editSpuShopCategory(spuId,scThirdId);
    }

    @ApiOperation("批量设置商品商家类目")
    @PostMapping("/editBatchSpuShopCategory")
    public BaseResp editBatchSpuShopCategory(@RequestBody List<EditSpuShopCategoryReq> req) {
        return productService.editBatchSpuShopCategory(req);
    }
}
